package bean;

import javax.faces.event.ActionEvent;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.adf.share.ADFContext;
import oracle.adf.view.rich.component.rich.RichPopup;

import oracle.adf.view.rich.context.AdfFacesContext;
import oracle.adf.view.rich.event.DialogEvent;

import oracle.adf.view.rich.event.DialogEvent.Outcome;

import oracle.adf.view.rich.event.PopupCanceledEvent;

import oracle.binding.BindingContainer;
import oracle.binding.OperationBinding;

import oracle.jbo.Row;

import util.ADFUtil;

public class ResourceBean {
    private RichPopup resourcePopup;

    public ResourceBean() {
    }

    /**
     *
     * @return
     */
    public BindingContainer getBindings() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();
    }
    
    
    public void setResourcePopup(RichPopup resourcePopup) {
        this.resourcePopup = resourcePopup;
    }

    public RichPopup getResourcePopup() {
        return resourcePopup;
    }
    
    /**
     *
     * @param actionEvent
     */
    public void addResource(ActionEvent actionEvent) {
        ADFUtil.setEL("#{viewScope.operation}", "create");
         RichPopup.PopupHints ph = new RichPopup.PopupHints();
        resourcePopup.show(ph); //Show popup

    }

   /**
     *
     * @param dialogEvent
     */
    public void resourceDialog(DialogEvent dialogEvent) {
        Outcome outcome = dialogEvent.getOutcome();
        if (outcome.equals(Outcome.ok)) {
            ADFUtil.setEL("#{viewScope.operation}", "");
           ADFUtil.invokeEL("#{bindings.Commit.execute}");
        }
    }

    public void resourcePopupClose(PopupCanceledEvent popupCanceledEvent) {
        ADFUtil.setEL("#{viewScope.operation}", "");
        ADFUtil.invokeEL("#{bindings.Rollback.execute}");      
        
    }

    
}
